package com.qzboot.basic.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.qzboot.basic.service.mapper.SysRoleMenuMapper;
import com.qzboot.facade.entity.SysRoleMenu;
import com.qzboot.facade.service.SysRoleMenuService;
import com.qzboot.facade.support.CrudServiceImpl;
import org.apache.dubbo.config.annotation.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author zengzhihong
 * @date 2019-12-16
 */
@Service
public class SysRoleMenuServiceImpl extends CrudServiceImpl<SysRoleMenuMapper, SysRoleMenu> implements SysRoleMenuService {

    @Override
    public boolean removeByRoleId(Long roleId) {
        return SqlHelper.retBool(baseMapper.delete(Wrappers.<SysRoleMenu>lambdaQuery().eq(SysRoleMenu::getRoleId, roleId)));
    }

    @Override
    public List<Long> listMenuIdByRoleId(Long roleId) {
        List<SysRoleMenu> roleMenuList = baseMapper.selectList(Wrappers.<SysRoleMenu>lambdaQuery().select(SysRoleMenu::getMenuId).eq(SysRoleMenu::getRoleId, roleId));
        return roleMenuList.stream().map(SysRoleMenu::getMenuId).collect(Collectors.toList());
    }

    @Override
    public boolean removeByMenuIdList(List<Long> menuIdList) {
        return SqlHelper.retBool(baseMapper.delete(Wrappers.<SysRoleMenu>lambdaQuery().in(SysRoleMenu::getMenuId, menuIdList)));
    }
}
